package com.lzyjkz.quick_system.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.lzyjkz.quick_system.entity.SysUser;
import com.lzyjkz.quick_system.mapper.SysUserMapper;
import com.lzyjkz.quick_system.service.SysUserService;
import lombok.RequiredArgsConstructor;
import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.stereotype.Service;

@Service
@RequiredArgsConstructor
public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> implements SysUserService {
    private final PasswordEncoder passwordEncoder;
    @Override
    public String register(SysUser sysUser) {
        sysUser.setNickname(sysUser.getUsername());
        if (this.lambdaQuery().eq(SysUser::getUsername, sysUser.getUsername()).exists()) {
            return "用户名已存在";
        }
        sysUser.setPassword(passwordEncoder.encode(sysUser.getPassword()));
        this.save(sysUser);
        return "注册成功";
    }
}
